package com.prtek.reminder.model;

import com.prtek.reminder.bean.Notes;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

/**
 * Created by jarly on 2018/9/29.
 */

public class MainModel implements IMainModel {

  public static Calendar mCalendar = Calendar.getInstance();
  private OnCompleteListener mCompleteListener;
  private ReminderDao mReminderDao;

  @Override public void onLoadData(OnCompleteListener completeListener) {
    mCompleteListener = completeListener;
    mReminderDao = ReminderDaoImpl.getInstance();
    mCalendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    refreshData();
  }

  @Override public void refreshData() {
    final long time = mCalendar.getTime().getTime();
    List<Notes> createNotes = mReminderDao.getNotesList();
    final List<Notes> mExpiredNotes = mReminderDao.getExpiredNotesList(time);
    mCompleteListener.onComplete(createNotes, mExpiredNotes);
  }

  @Override public void deleteNotes(Notes notes) {
    mReminderDao.deleteNotes(notes);
  }
}
